version 18.0               // version control
set processors 8           // to ensure replicability across different numbers of cores
clear all                  // clear existing data
macro drop _all            // and macros, clean slate
set seed 20220619          // set seed

*-------------------------------------------------------
* project: daylight saving time (dst)
*-------------------------------------------------------

local pgm  "dst-data02_solar_county_avg"    // file name
local who  "Muzhe Yang"                     // author
local dte  "2022-06-19"                     // created date
local dte2 "`c(current_date)'"              // last run date
local tag  "`pgm'.do, created by `who' on `dte', last run on `dte2'"

capture log close
log using "code\management\\`pgm'.txt", replace text
display "`tag'"

use "data_clean\solar\dst-data02_solar_county_daily", clear
collapse (mean) county_lat ///
         (mean) county_lon ///
		 (mean) daylight_dur_avg = daylight_duration ///
		 (sd)    daylight_dur_sd = daylight_duration ///
		 (min)  daylight_dur_min = daylight_duration ///
		 (max)  daylight_dur_max = daylight_duration, ///
         by(CountyFIPS)

label variable county_lat       "latitude of the county's centroid"
label variable county_lon       "longitude of the county's centroid"
label variable daylight_dur_avg "avgerage of daylight hours per day, county level"
label variable daylight_dur_sd  "standard deviation of daylight hours per day, county level"
label variable daylight_dur_min "minimum of daylight hours per day, county level"
label variable daylight_dur_max "maximum of daylight hours per day, county level"

sort CountyFIPS 
codebook, compact
compress
save "data_clean\solar\\`pgm'.dta", replace
export excel "data_clean\solar\\`pgm'.xlsx", sheet("county avg") firstrow(variables) replace

log close
exit